/*
 * All rights Reserved, Designed By HerDao
 * Copyright:    Copyright(C) 2020-2099
 * Company:      HerDao Ltd.
 */
package com.boots.redission.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redission配置文件
 * @author：OprCalf
 * @date：2021-1-9 15:03:35
 */
@Configuration
public class RedissonConfig {

    @Value("${boots.redis.host}")
    private String host;

    @Value("${boots.redis.port}")
    private String port;

    @Value("${boots.redis.password}")
    private String password;

    /**
     * 初始化Redission连接客户端
     * @author OprCalf
     * @Date 2021-1-9 15:10:08
     * @return RedissonClient
     */
    @Bean
    public RedissonClient initRedisson() {
        final Config config = new Config();
        // 设置数据传输模式为NIO
        config.setTransportMode(TransportMode.NIO);
        // 采用单体redis进行配置
        final SingleServerConfig singleConfig = config.useSingleServer();
        // 配置连接地址
        singleConfig.setAddress("redis://" + host + ":" + port);
        // 配置密码
        singleConfig.setPassword(password);
        return Redisson.create(config);
    }

}
